<template>
  <el-button round @click="editForm"
             :disabled="!enable">{{ button.buttonName }}
  </el-button>
</template>
<script setup>
import {DefaultMenuButton} from '@/components/form/DefaultFormDefinition';
import {computed, getCurrentInstance} from 'vue';
import {isNotEmpty} from '@/utils/CommonUtils';

const internalInstance = getCurrentInstance();
const global = internalInstance.appContext.config.globalProperties;

defineOptions({
  name: 'EditFormButton'
});
const emits = defineEmits(['reload']);
const props = defineProps({
  button: DefaultMenuButton,
  selections: {
    type: Array,
    default: () => [],
  },
  formDefinition: undefined
});

function isProcessForm() {
  try {
    return props.formDefinition.form.processForm;
  } catch (e) {
  }
  return false;
}

function editForm() {
    editProcessForm();
}

function editProcessForm() {
  let formData = props.selections[0];
  let url = `/plat/work/formEdit?action=edit&fullScreen=1&businessId=${formData.id}&viewActionId=${props.button.pcViewActionId}&processDefinitionId=${props.button.process_definition_id}`;
  global.$windowManager.open(url, {
    title: props.button.buttonName,
    close: () => emits('reload')
  });
}

const enable = computed(() => {
  if (isNotEmpty(props.selections) && props.selections.length === 1) return true;
  return false;
});

</script>
